package svc

import (
	"context"
	"gozerogateway/api/internal/svc"
	"gozerogateway/api/internal/types"
	"gozerogateway/rpc/svc/svcclient"

	"encoding/json"
	"github.com/zeromicro/go-zero/core/logx"
)

type ServiceDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewServiceDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceDeleteLogic {
	return &ServiceDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ServiceDeleteLogic) ServiceDelete(req *types.ServiceDeleteReq) error {
	// todo: add your logic here and delete this line

	_, err := l.svcCtx.Svc.ServiceDelete(l.ctx, &svcclient.ServiceDeleteReq{
		ID: req.ID,
	})
	if err != nil {
		reqStr, _ := json.Marshal(req)
		logx.WithContext(l.ctx).Errorf("delete service error,id error,param:%s", reqStr)
		return err
	}
	return nil
}
